﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using HYSoft.IDAL;
using HYSoft.DBUtility;//Please add references
namespace HYSoft.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:bpjginfo
	/// </summary>
	public partial class bpjginfo:Ibpjginfo
	{
		public bpjginfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ljbp_sec_id", "tb_bpjginfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(DateTime cldate,int ljbp_sec_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from tb_bpjginfo");
			strSql.Append(" where cldate=@cldate and ljbp_sec_id=@ljbp_sec_id ");
			SqlParameter[] parameters = {
					new SqlParameter("@cldate", SqlDbType.DateTime),
					new SqlParameter("@ljbp_sec_id", SqlDbType.Int,4)			};
			parameters[0].Value = cldate;
			parameters[1].Value = ljbp_sec_id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(HYSoft.Model.bpjginfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into tb_bpjginfo(");
			strSql.Append("cldate,ljbp_stab_coef,ljbp_warn_grade,ljbpjyl,ljbp_sec_id,ljbpwy,ljbpsbbx,ljbpqcqxj_qx,ljbpqcqxj_zx,ljbp_collaps_l,ljbp_collaps_w,ljbp_collaps_cub,ljbp_influenc_w,ljbp_influenc_time,ljbptyl,ljbpjgyl,ljbp_electro_sta,ljbp_distransducer_sta,ljbp_tilt_sta)");
			strSql.Append(" values (");
			strSql.Append("@cldate,@ljbp_stab_coef,@ljbp_warn_grade,@ljbpjyl,@ljbp_sec_id,@ljbpwy,@ljbpsbbx,@ljbpqcqxj_qx,@ljbpqcqxj_zx,@ljbp_collaps_l,@ljbp_collaps_w,@ljbp_collaps_cub,@ljbp_influenc_w,@ljbp_influenc_time,@ljbptyl,@ljbpjgyl,@ljbp_electro_sta,@ljbp_distransducer_sta,@ljbp_tilt_sta)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@cldate", SqlDbType.DateTime),
					new SqlParameter("@ljbp_stab_coef", SqlDbType.Float,8),
					new SqlParameter("@ljbp_warn_grade", SqlDbType.Char,50),
					new SqlParameter("@ljbpjyl", SqlDbType.Int,4),
					new SqlParameter("@ljbp_sec_id", SqlDbType.Int,4),
					new SqlParameter("@ljbpwy", SqlDbType.Int,4),
					new SqlParameter("@ljbpsbbx", SqlDbType.Int,4),
					new SqlParameter("@ljbpqcqxj_qx", SqlDbType.Float,8),
					new SqlParameter("@ljbpqcqxj_zx", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_l", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_w", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_cub", SqlDbType.Float,8),
					new SqlParameter("@ljbp_influenc_w", SqlDbType.Int,4),
					new SqlParameter("@ljbp_influenc_time", SqlDbType.Int,4),
					new SqlParameter("@ljbptyl", SqlDbType.Int,4),
					new SqlParameter("@ljbpjgyl", SqlDbType.Int,4),
					new SqlParameter("@ljbp_electro_sta", SqlDbType.Char,50),
					new SqlParameter("@ljbp_distransducer_sta", SqlDbType.Char,50),
					new SqlParameter("@ljbp_tilt_sta", SqlDbType.Char,50)};
			parameters[0].Value = model.cldate;
			parameters[1].Value = model.ljbp_stab_coef;
			parameters[2].Value = model.ljbp_warn_grade;
			parameters[3].Value = model.ljbpjyl;
			parameters[4].Value = model.ljbp_sec_id;
			parameters[5].Value = model.ljbpwy;
			parameters[6].Value = model.ljbpsbbx;
			parameters[7].Value = model.ljbpqcqxj_qx;
			parameters[8].Value = model.ljbpqcqxj_zx;
			parameters[9].Value = model.ljbp_collaps_l;
			parameters[10].Value = model.ljbp_collaps_w;
			parameters[11].Value = model.ljbp_collaps_cub;
			parameters[12].Value = model.ljbp_influenc_w;
			parameters[13].Value = model.ljbp_influenc_time;
			parameters[14].Value = model.ljbptyl;
			parameters[15].Value = model.ljbpjgyl;
			parameters[16].Value = model.ljbp_electro_sta;
			parameters[17].Value = model.ljbp_distransducer_sta;
			parameters[18].Value = model.ljbp_tilt_sta;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HYSoft.Model.bpjginfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_bpjginfo set ");
			strSql.Append("ljbp_stab_coef=@ljbp_stab_coef,");
			strSql.Append("ljbp_warn_grade=@ljbp_warn_grade,");
			strSql.Append("ljbpjyl=@ljbpjyl,");
			strSql.Append("ljbpwy=@ljbpwy,");
			strSql.Append("ljbpsbbx=@ljbpsbbx,");
			strSql.Append("ljbpqcqxj_qx=@ljbpqcqxj_qx,");
			strSql.Append("ljbpqcqxj_zx=@ljbpqcqxj_zx,");
			strSql.Append("ljbp_collaps_l=@ljbp_collaps_l,");
			strSql.Append("ljbp_collaps_w=@ljbp_collaps_w,");
			strSql.Append("ljbp_collaps_cub=@ljbp_collaps_cub,");
			strSql.Append("ljbp_influenc_w=@ljbp_influenc_w,");
			strSql.Append("ljbp_influenc_time=@ljbp_influenc_time,");
			strSql.Append("ljbptyl=@ljbptyl,");
			strSql.Append("ljbpjgyl=@ljbpjgyl,");
			strSql.Append("ljbp_electro_sta=@ljbp_electro_sta,");
			strSql.Append("ljbp_distransducer_sta=@ljbp_distransducer_sta,");
			strSql.Append("ljbp_tilt_sta=@ljbp_tilt_sta");
			strSql.Append(" where ljid=@ljid");
			SqlParameter[] parameters = {
					new SqlParameter("@ljbp_stab_coef", SqlDbType.Float,8),
					new SqlParameter("@ljbp_warn_grade", SqlDbType.Char,50),
					new SqlParameter("@ljbpjyl", SqlDbType.Int,4),
					new SqlParameter("@ljbpwy", SqlDbType.Int,4),
					new SqlParameter("@ljbpsbbx", SqlDbType.Int,4),
					new SqlParameter("@ljbpqcqxj_qx", SqlDbType.Float,8),
					new SqlParameter("@ljbpqcqxj_zx", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_l", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_w", SqlDbType.Float,8),
					new SqlParameter("@ljbp_collaps_cub", SqlDbType.Float,8),
					new SqlParameter("@ljbp_influenc_w", SqlDbType.Int,4),
					new SqlParameter("@ljbp_influenc_time", SqlDbType.Int,4),
					new SqlParameter("@ljbptyl", SqlDbType.Int,4),
					new SqlParameter("@ljbpjgyl", SqlDbType.Int,4),
					new SqlParameter("@ljbp_electro_sta", SqlDbType.Char,50),
					new SqlParameter("@ljbp_distransducer_sta", SqlDbType.Char,50),
					new SqlParameter("@ljbp_tilt_sta", SqlDbType.Char,50),
					new SqlParameter("@ljid", SqlDbType.Int,4),
					new SqlParameter("@cldate", SqlDbType.DateTime),
					new SqlParameter("@ljbp_sec_id", SqlDbType.Int,4)};
			parameters[0].Value = model.ljbp_stab_coef;
			parameters[1].Value = model.ljbp_warn_grade;
			parameters[2].Value = model.ljbpjyl;
			parameters[3].Value = model.ljbpwy;
			parameters[4].Value = model.ljbpsbbx;
			parameters[5].Value = model.ljbpqcqxj_qx;
			parameters[6].Value = model.ljbpqcqxj_zx;
			parameters[7].Value = model.ljbp_collaps_l;
			parameters[8].Value = model.ljbp_collaps_w;
			parameters[9].Value = model.ljbp_collaps_cub;
			parameters[10].Value = model.ljbp_influenc_w;
			parameters[11].Value = model.ljbp_influenc_time;
			parameters[12].Value = model.ljbptyl;
			parameters[13].Value = model.ljbpjgyl;
			parameters[14].Value = model.ljbp_electro_sta;
			parameters[15].Value = model.ljbp_distransducer_sta;
			parameters[16].Value = model.ljbp_tilt_sta;
			parameters[17].Value = model.ljid;
			parameters[18].Value = model.cldate;
			parameters[19].Value = model.ljbp_sec_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ljid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tb_bpjginfo ");
			strSql.Append(" where ljid=@ljid");
			SqlParameter[] parameters = {
					new SqlParameter("@ljid", SqlDbType.Int,4)
			};
			parameters[0].Value = ljid;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(DateTime cldate,int ljbp_sec_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tb_bpjginfo ");
			strSql.Append(" where cldate=@cldate and ljbp_sec_id=@ljbp_sec_id ");
			SqlParameter[] parameters = {
					new SqlParameter("@cldate", SqlDbType.DateTime),
					new SqlParameter("@ljbp_sec_id", SqlDbType.Int,4)			};
			parameters[0].Value = cldate;
			parameters[1].Value = ljbp_sec_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ljidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tb_bpjginfo ");
			strSql.Append(" where ljid in ("+ljidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HYSoft.Model.bpjginfo GetModel(int ljid)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ljid,cldate,ljbp_stab_coef,ljbp_warn_grade,ljbpjyl,ljbp_sec_id,ljbpwy,ljbpsbbx,ljbpqcqxj_qx,ljbpqcqxj_zx,ljbp_collaps_l,ljbp_collaps_w,ljbp_collaps_cub,ljbp_influenc_w,ljbp_influenc_time,ljbptyl,ljbpjgyl,ljbp_electro_sta,ljbp_distransducer_sta,ljbp_tilt_sta from tb_bpjginfo ");
			strSql.Append(" where ljid=@ljid");
			SqlParameter[] parameters = {
					new SqlParameter("@ljid", SqlDbType.Int,4)
			};
			parameters[0].Value = ljid;

			HYSoft.Model.bpjginfo model=new HYSoft.Model.bpjginfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public HYSoft.Model.bpjginfo DataRowToModel(DataRow row)
		{
			HYSoft.Model.bpjginfo model=new HYSoft.Model.bpjginfo();
			if (row != null)
			{
				if(row["ljid"]!=null && row["ljid"].ToString()!="")
				{
					model.ljid=int.Parse(row["ljid"].ToString());
				}
				if(row["cldate"]!=null && row["cldate"].ToString()!="")
				{
					model.cldate=DateTime.Parse(row["cldate"].ToString());
				}
				if(row["ljbp_stab_coef"]!=null && row["ljbp_stab_coef"].ToString()!="")
				{
					model.ljbp_stab_coef=decimal.Parse(row["ljbp_stab_coef"].ToString());
				}
				if(row["ljbp_warn_grade"]!=null)
				{
					model.ljbp_warn_grade=row["ljbp_warn_grade"].ToString();
				}
				if(row["ljbpjyl"]!=null && row["ljbpjyl"].ToString()!="")
				{
					model.ljbpjyl=int.Parse(row["ljbpjyl"].ToString());
				}
				if(row["ljbp_sec_id"]!=null && row["ljbp_sec_id"].ToString()!="")
				{
					model.ljbp_sec_id=int.Parse(row["ljbp_sec_id"].ToString());
				}
				if(row["ljbpwy"]!=null && row["ljbpwy"].ToString()!="")
				{
					model.ljbpwy=int.Parse(row["ljbpwy"].ToString());
				}
				if(row["ljbpsbbx"]!=null && row["ljbpsbbx"].ToString()!="")
				{
					model.ljbpsbbx=int.Parse(row["ljbpsbbx"].ToString());
				}
				if(row["ljbpqcqxj_qx"]!=null && row["ljbpqcqxj_qx"].ToString()!="")
				{
					model.ljbpqcqxj_qx=decimal.Parse(row["ljbpqcqxj_qx"].ToString());
				}
				if(row["ljbpqcqxj_zx"]!=null && row["ljbpqcqxj_zx"].ToString()!="")
				{
					model.ljbpqcqxj_zx=decimal.Parse(row["ljbpqcqxj_zx"].ToString());
				}
				if(row["ljbp_collaps_l"]!=null && row["ljbp_collaps_l"].ToString()!="")
				{
					model.ljbp_collaps_l=decimal.Parse(row["ljbp_collaps_l"].ToString());
				}
				if(row["ljbp_collaps_w"]!=null && row["ljbp_collaps_w"].ToString()!="")
				{
					model.ljbp_collaps_w=decimal.Parse(row["ljbp_collaps_w"].ToString());
				}
				if(row["ljbp_collaps_cub"]!=null && row["ljbp_collaps_cub"].ToString()!="")
				{
					model.ljbp_collaps_cub=decimal.Parse(row["ljbp_collaps_cub"].ToString());
				}
				if(row["ljbp_influenc_w"]!=null && row["ljbp_influenc_w"].ToString()!="")
				{
					model.ljbp_influenc_w=int.Parse(row["ljbp_influenc_w"].ToString());
				}
				if(row["ljbp_influenc_time"]!=null && row["ljbp_influenc_time"].ToString()!="")
				{
					model.ljbp_influenc_time=int.Parse(row["ljbp_influenc_time"].ToString());
				}
				if(row["ljbptyl"]!=null && row["ljbptyl"].ToString()!="")
				{
					model.ljbptyl=int.Parse(row["ljbptyl"].ToString());
				}
				if(row["ljbpjgyl"]!=null && row["ljbpjgyl"].ToString()!="")
				{
					model.ljbpjgyl=int.Parse(row["ljbpjgyl"].ToString());
				}
				if(row["ljbp_electro_sta"]!=null)
				{
					model.ljbp_electro_sta=row["ljbp_electro_sta"].ToString();
				}
				if(row["ljbp_distransducer_sta"]!=null)
				{
					model.ljbp_distransducer_sta=row["ljbp_distransducer_sta"].ToString();
				}
				if(row["ljbp_tilt_sta"]!=null)
				{
					model.ljbp_tilt_sta=row["ljbp_tilt_sta"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ljid,cldate,ljbp_stab_coef,ljbp_warn_grade,ljbpjyl,ljbp_sec_id,ljbpwy,ljbpsbbx,ljbpqcqxj_qx,ljbpqcqxj_zx,ljbp_collaps_l,ljbp_collaps_w,ljbp_collaps_cub,ljbp_influenc_w,ljbp_influenc_time,ljbptyl,ljbpjgyl,ljbp_electro_sta,ljbp_distransducer_sta,ljbp_tilt_sta ");
			strSql.Append(" FROM tb_bpjginfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ljid,cldate,ljbp_stab_coef,ljbp_warn_grade,ljbpjyl,ljbp_sec_id,ljbpwy,ljbpsbbx,ljbpqcqxj_qx,ljbpqcqxj_zx,ljbp_collaps_l,ljbp_collaps_w,ljbp_collaps_cub,ljbp_influenc_w,ljbp_influenc_time,ljbptyl,ljbpjgyl,ljbp_electro_sta,ljbp_distransducer_sta,ljbp_tilt_sta ");
			strSql.Append(" FROM tb_bpjginfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM tb_bpjginfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ljid desc");
			}
			strSql.Append(")AS Row, T.*  from tb_bpjginfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "tb_bpjginfo";
			parameters[1].Value = "ljid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

